import React, { useState, useEffect } from "react";
import CountUp from "react-countup";
import style from "./style.less";

export default () => {
  const [config, setConfig] = useState({ start: 0, end: 25635, duration: 1, useEasing: true, useGrouping: true, separator: "," });
  useEffect(() => {
    let timer = setInterval(() => {
      setConfig((c) => {
        let start = c.end;
        let end = c.end + Math.round(Math.random() * 200000);
        return { ...c, start, end };
      });
    }, 2000);
    return () => {
      clearInterval(timer);
    };
  }, []);
  return (
    <>
      <CountUp {...config} className={style["count-wrap"]}></CountUp>
    </>
  );
};
